﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProgNetAppBlocks.Forms;

namespace MiniKsiegowosc.Ustawienia.RokKsiegowy
{
    public partial class FormRokKsiegowy : ProgNetSpreadSheetForm
    {
        public FormRokKsiegowy()
        {
            InitializeComponent();
        }
        protected override bool ValidateRow(DataRow r, DevExpress.XtraGrid.Views.Grid.GridView gv)
        {
            bool result = base.ValidateRow(r, gv);
            if (result && gv == gvMain)
            {
                if (!r.IsColumnUnique("STP_LP_ROK"))
                {
                    r.SetColumnValue("STP_LP_ROK", "Rok powienien być unikalny.");
                    this.AddError("Rok powienien być unikalny.");
                    result = false;
                }
            }
            return result;
        }

        protected override bool AllowDeleteRow(DataRow r)
        {
            if (r.RowState != DataRowState.Added)
            {
                if (Wrk.WrkTools.RokHasData(r["STP_LP_ROK"].AsInt()))
                {
                    if (this.ShowDxYNQuestionDialog("Rok posiada faktury. Chcesz go usunąć?") == System.Windows.Forms.DialogResult.Yes)
                        return true;
                    return false;
                }
            }
            return true;
        }
    }
}
